package com.eastfair.home.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.service.HomeReportVenueDrawingCategoryAuditService;
import com.eastfair.home.vo.ReportVenueDrawingCategoryVO;
import com.eastfair.venuebooking.api.ReportVenueDrawingCategoryAuditFeign;
import com.eastfair.venueservice.vo.ReportVenueDrawingCategoryAuditVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 一键报馆图纸分类审核 Service.
 *
 * @author dqq
 * @date 2022 /9/16
 */
@Service
@Slf4j
public class HomeReportVenueDrawingCategoryAuditServiceImpl implements HomeReportVenueDrawingCategoryAuditService {

    @Resource
    private ReportVenueDrawingCategoryAuditFeign reportVenueDrawingCategoryAuditFeign;

    @Override
    public List<ReportVenueDrawingCategoryAuditVO> queryByReportVenueSpaceNumber(String reportVenueSpaceNumber) {
        log.info("queryByReportVenueSpaceNumber - 一键报馆号查询图纸分类审核, reportVenueSpaceNumber={}", reportVenueSpaceNumber);
        R<List<ReportVenueDrawingCategoryAuditVO>> result = reportVenueDrawingCategoryAuditFeign.queryByReportVenueSpaceNumber(reportVenueSpaceNumber);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public List<ReportVenueDrawingCategoryVO> listCategoryVOByReportVenueSpaceNumber(String reportVenueSpaceNumber) {
        List<ReportVenueDrawingCategoryAuditVO> voList = queryByReportVenueSpaceNumber(reportVenueSpaceNumber);
        if (voList == null || voList.isEmpty()) {
            return Collections.emptyList();
        }
        return voList
                .stream()
                .map(auditVO -> BeanUtil.toBean(auditVO, ReportVenueDrawingCategoryVO.class))
                .collect(Collectors.toList());
    }
}